<?php
defined('IN_IA') or exit('Access Denied');
global $_W, $_GPC;
load()->func('file');
mkdirs(ATTACHMENT_ROOT . '/bsht_tbk/' . $_W['uniacid']);
set_time_limit(60);
include_once '../addons/bsht_tbk/plus/excel/oleread.php';
include_once '../addons/bsht_tbk/plus/excel/excel.php';
$error = $_FILES["txtfile1"]["error"];
if (!empty($_FILES['txtfile1']['name']) && $error == UPLOAD_ERR_OK) {
	$tmp_name = $_FILES["txtfile1"]["tmp_name"];
	$name = $_FILES["txtfile1"]["name"];
	$filename = ATTACHMENT_ROOT . '/bsht_tbk/' . $_W['uniacid'] . '/jx-bsht-tbk-' . date('Ymdhis') . '.' . pathinfo($name, PATHINFO_EXTENSION);
	if (move_uploaded_file($tmp_name, $filename)) {
		$xls = new Spreadsheet_Excel_Reader();
		$xls->setOutputEncoding('utf-8');
		$xls->read($filename);
		for ($i = 2; $i <= $xls->sheets[0]['numRows']; $i++) {
			$data_values[] = $xls->sheets[0]['cells'][$i];
		}
	}
	$inert_sql = "INSERT INTO " . tablename('bsht_tbk_all_caiji_jx') . " (*) ";
	$insert_val = "";
	$count = 0;
	$cateid = 0;
	foreach ($data_values as $value) {
		if ($value[1] == '') {
			break;
		}
		if ($value[1] != '') {
			$cate = pdo_fetch('select id,itemid from ' . tablename('bsht_tbk_all_caiji_jx') . " where itemid = '{$value[1]}' and uniacid = '{$_W['uniacid']}' limit 1");
			if (empty($cate)) {
				$value[5] = str_replace("/", "", $value[5]);
				$value[5] = mb_substr($value[5], 0, 2, 'utf-8');
				if ($value[5] == "女装") {
					$jxid = 1;
				}
				if ($value[5] == "男装") {
					$jxid = 2;
				}
				if ($value[5] == "女鞋") {
					$jxid = 3;
				}
				if ($value[5] == "流行") {
					$jxid = 3;
				}
				if ($value[5] == "箱包") {
					$jxid = 4;
				}
				if ($value[5] == "童装") {
					$jxid = 5;
				}
				if ($value[5] == "童鞋") {
					$jxid = 5;
				}
				if ($value[5] == "尿片") {
					$jxid = 5;
				}
				if ($value[5] == "孕妇") {
					$jxid = 5;
				}
				if ($value[5] == "玩具") {
					$jxid = 5;
				}
				if ($value[5] == "美容") {
					$jxid = 6;
				}
				if ($value[5] == "收纳") {
					$jxid = 7;
				}
				if ($value[5] == "家庭") {
					$jxid = 7;
				}
				if ($value[5] == "居家") {
					$jxid = 7;
				}
				if ($value[5] == "洗护") {
					$jxid = 7;
				}
				if ($value[5] == "餐饮") {
					$jxid = 7;
				}
				if ($value[5] == "床上") {
					$jxid = 8;
				}
				if ($value[5] == "厨房") {
					$jxid = 9;
				}
				if ($value[5] == "个人") {
					$jxid = 10;
				}
				if ($value[5] == "传统") {
					$jxid = 10;
				}
				if ($value[5] == "女士") {
					$jxid = 11;
				}
				if ($value[5] == "饰品") {
					$jxid = 12;
				}
				if ($value[5] == "服饰") {
					$jxid = 12;
				}
				if ($value[5] == "手表") {
					$jxid = 13;
				}
				if ($value[5] == "3C") {
					$jxid = 14;
				}
				if ($value[5] == "闪存") {
					$jxid = 14;
				}
				if ($value[5] == "网络") {
					$jxid = 14;
				}
				if ($value[5] == "电子") {
					$jxid = 14;
				}
				if ($value[5] == "运动") {
					$jxid = 15;
				}
				if ($value[5] == "零食") {
					$jxid = 16;
				}
				if ($value[5] == "茶") {
					$jxid = 17;
				}
				if ($value[5] == "咖啡") {
					$jxid = 17;
				}
				if ($value[5] == "节庆") {
					$jxid = 18;
				}
				if ($value[5] == "生活") {
					$jxid = 19;
				}
				if ($value[5] == "宠物") {
					$jxid = 20;
				}
				if ($value[5] == "水产") {
					$jxid = 21;
				}
				if ($value[5] == "粮油") {
					$jxid = 21;
				}
				if ($value[5] == "OT") {
					$jxid = 22;
				}
				if ($value[5] == "ZI") {
					$jxid = 23;
				}
				if ($value[5] == "隐形") {
					$jxid = 23;
				}
				if ($value[5] == "汽车") {
					$jxid = 24;
				}
				if ($value[5] == "家装") {
					$jxid = 25;
				}
				if ($value[5] == "基础") {
					$jxid = 25;
				}
				if ($value[5] == "五金") {
					$jxid = 25;
				}
				if ($value[14] == '天猫') {
					$istmall = 1;
				} else {
					$istmall = 0;
				}
				$cate_data = array('uniacid' => $_W['uniacid'], 'displayorder' => '0', 'itemid' => $value[1], 'cate_id' => $jxid, 'cate_name' => $value[5], 'title' => $value[2], 'd_title' => $value[2], 'itempic' => $value[3], 'shoptitle' => $value[13], 'itemfee' => $value[7], 'itemmsell' => $value[8], 'istmall' => $istmall, 'itemsurl' => $value[6], 'itemurl' => $value[6], 'itemyhj_zl' => $value[16], 'itemyhj_yl' => $value[17], 'itemyhj_tit' => $value[18], 'itemyhj_stime' => $value[19], 'itemyhj_etime' => $value[20], 'itemyhj_url' => $value[22], 'shouru_bili' => $value[9], 'shouru_yongjin' => $value[10], 'quan_id' => $value[15], 'maijia_id' => $value[12], 'status' => 1, 'fm' => 'mrjx');
				$cate_data['quan_link'] = "http://shop.m.taobao.com/shop/coupon.htm?seller_id=" . $value[12] . "&activity_id=" . $value[15];
				pdo_insert('bsht_tbk_all_caiji_jx', $cate_data);
				$cateid = pdo_insertid();
			} else {
				$cateid = $cate['id'];
			}
			continue;
		}
		if (!empty($insert_val)) {
			$insert_val .= ", ";
		}
		$insert_val .= " ( * ) ";
		$count++;
	}
	message('导入成功！', referer(), 'success');
} else {
	message('导入失败，请检查文件或运行环境！', referer(), 'error');
}